package com.zhentao.equipment.controller;

import com.zhentao.equipment.service.DeviceMaintenanceService;
import com.zhentao.pojo.DeviceMaintenancePlan;
import com.zhentao.pojo.DeviceMaintenanceRecord;
import com.zhentao.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 维护计划与记录接口
 */
@RestController
@RequestMapping("/api/maintenance")
@CrossOrigin(origins = "*")
public class DeviceMaintenanceController {

    @Autowired
    private DeviceMaintenanceService service;

    // 新增/更新计划
    @PostMapping("/plans")
    public ResultVo savePlan(@RequestBody DeviceMaintenancePlan plan) { return service.savePlan(plan); }

    // 删除计划
    @DeleteMapping("/plans/{id}")
    public ResultVo deletePlan(@PathVariable Long id) { return service.deletePlan(id); }

    // 计划分页
    @GetMapping("/plans")
    public ResultVo planPage(@RequestParam(required = false) Integer pageNum,
                             @RequestParam(required = false) Integer pageSize,
                             @RequestParam(required = false) Long deviceId,
                             @RequestParam(required = false) Integer status) {
        return service.planPage(pageNum, pageSize, deviceId, status);
    }

    // 计划状态流转
    @PatchMapping("/plans/{id}/status")
    public ResultVo changeStatus(@PathVariable Long id, @RequestParam Integer status) {
        return service.changePlanStatus(id, status);
    }

    // 新增维护记录
    @PostMapping("/records")
    public ResultVo addRecord(@RequestBody DeviceMaintenanceRecord record) { return service.addRecord(record); }

    // 维护记录分页
    @GetMapping("/records")
    public ResultVo recordPage(@RequestParam(required = false) Integer pageNum,
                               @RequestParam(required = false) Integer pageSize,
                               @RequestParam(required = false) Long deviceId,
                               @RequestParam(required = false) Long planId) {
        return service.recordPage(pageNum, pageSize, deviceId, planId);
    }
}





